using System;
using System.Collections.Generic;
using System.Text;
using Ares.PacketHandlers;

namespace cb0tServer
{
    public partial class ServerCore
    {
        private void ProcessReceivedSCASPacket(SCASObject scas, byte id, AresDataPacket packet)
        {
            String name, text;
            UserObject user;
            ushort num;

            if (!scas.logged_in && id != 1)
            {
                scas.Disconnect();
                return;
            }

            switch (id)
            {
                case 1: // login
                    if (!scas.logged_in)
                    {
                        scas.scas_guid = packet.ReadGuid();
                        scas.scas_version = packet.ReadInt16();

                        if (this.OnSCASJoinCheck(scas))
                            this.OnSCASJoin(scas);
                        else
                            scas.Disconnect();
                    }

                    break;

                case 11: // vtopic to user
                    num = packet.ReadInt16();
                    text = packet.ReadString();
                    user = UserPool.GetUserById(num);

                    if (user != null)
                        Topics.SetVirtualTopic(user, text);

                    break;

                case 12: // vtopic to vroom
                    num = packet.ReadInt16();
                    text = packet.ReadString();
                    Topics.SetVirtualTopic(num, text);
                    break;

                case 13: // vtopic to all
                    text = packet.ReadString();
                    Topics.SetVirtualTopic(text);
                    break;

                case 21: // vurl to user
                    num = packet.ReadInt16();
                    name = packet.ReadString();
                    text = packet.ReadString();
                    user = UserPool.GetUserById(num);

                    if (user != null)
                        user.SendOutboundPacket(ServerOutboundPackets.UrlPacket(name, text));

                    break;

                case 22: // vurl to vroom
                    num = packet.ReadInt16();
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.Broadcast(num, ServerOutboundPackets.UrlPacket(name, text));
                    break;

                case 23: // vurl to all
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.Broadcast(ServerOutboundPackets.UrlPacket(name, text));
                    break;

                case 30: // announce all
                    text = packet.ReadString();
                    UserPool.Broadcast(ServerOutboundPackets.AnnoucePacket(text));

                    if (this.link_client.IsLinking())
                        this.link_client.SendOutboundPacket(ServerOutboundPackets.LinkAnnouncePacket(text));

                    break;

                case 31: // announce admin
                    text = packet.ReadString();
                    UserPool.BroadcastToAdmins(ServerOutboundPackets.AnnoucePacket(text));
                    break;

                case 32: // announce host
                    text = packet.ReadString();
                    UserPool.BroadcastToHosts(ServerOutboundPackets.AnnoucePacket(text));
                    break;

                case 33: // announce vroom
                    num = packet.ReadInt16();
                    text = packet.ReadString();
                    UserPool.Broadcast(num, ServerOutboundPackets.AnnoucePacket(text));

                    if (num == 0)
                        if (this.link_client.IsLinking())
                            this.link_client.SendOutboundPacket(ServerOutboundPackets.LinkAnnouncePacket(text));

                    break;

                case 34: // announce user
                    num = packet.ReadInt16();
                    text = packet.ReadString();
                    user = UserPool.GetUserById(num);

                    if (user != null)
                        user.SendOutboundPacket(ServerOutboundPackets.AnnoucePacket(text));

                    break;

                case 43: // public text
                    num = packet.ReadInt16();
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.Broadcast(num, ServerOutboundPackets.PublicTextPacket(name, text));
                    break;

                case 44: // emote text
                    num = packet.ReadInt16();
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.Broadcast(num, ServerOutboundPackets.EmoteTextPacket(name, text));
                    break;

                case 51: // pm all
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.Broadcast(ServerOutboundPackets.PMPacket(name, text));
                    break;

                case 52: // pm admins
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.BroadcastToAdmins(ServerOutboundPackets.PMPacket(name, text));
                    break;

                case 53: // pm hosts
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.BroadcastToHosts(ServerOutboundPackets.PMPacket(name, text));
                    break;

                case 54: // pm vroom
                    num = packet.ReadInt16();
                    name = packet.ReadString();
                    text = packet.ReadString();
                    UserPool.Broadcast(num, ServerOutboundPackets.PMPacket(name, text));
                    break;

                case 55: // pm user
                    num = packet.ReadInt16();
                    name = packet.ReadString();
                    text = packet.ReadString();
                    user = UserPool.GetUserById(num);

                    if (user != null)
                        user.SendOutboundPacket(ServerOutboundPackets.PMPacket(name, text));

                    break;

                default:
                    break;
            }
        }

    }
}
